

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

// 使用乾坤渲染--里面提供了几个生命周期钩子
renderWithQiankun({
  // 挂载时
  mount (props) {
    console.log('mount')
    render(props)
  },
  bootstrap () {
    console.log('bootstrap')
  },
  unmount (props) {
    console.log('unmount', props)
    //优化,切回主应用的时候,会导致app的颜色混乱,需要清除
    document.querySelector('#app').style.backgroundColor = 'white'


    //qiankun的优点,将子应用和主应用的源相同,可以共享localStorage里面的token

  },
})

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({})
}

//使用qiankun来render,里面包裹createApp.
function render (props = {}) {
  const { container } = props
  const app = createApp(App)
  app.use(router)
  app.mount(container ? container.querySelector("#app") : "#app")
}

//💕用qiankun来接管vue
// const app = createApp(App)

// app.use(router)

// app.mount('#app')
